<?php 
include 'load.php';

$login_error = false;
$login_success = false;

if(isset($_POST['username'])){
	$uname = $_POST['username'];
	$pass = $_POST['password'];
	
	
	
	if (preg_match("/^[\w\-\.]+@[\w\-]+(\.\w+)+$/", $uname)){
		$result = $snsdb->get_results("select * from sns_user where username='".$uname."' and password='".md5($pass)."'");
		if(count($result) == 0){
			$login_error = "您的用户名不存在或与密码不匹配，请重新登录！";
		}else{
			$user = $result[0];
			$_SESSION['user'] = $user;
			$login_success = true;
		}
	}else{
		$login_error = "您的用户名不是一个EMAIL地址，请重新登录！";
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <?php if ($login_success){?>
        <meta http-equiv="Refresh" content="3;url=<?php echo $root_path.'index.php';?>"></meta>
        <?php }?>
        <meta content="" />
        <title>登录--微博营销工具</title>
        <link href="<?php echo $root_path;?>style.css" rel="stylesheet" type="text/css" />
        <script type="javascript" src="<?php echo $root_path;?>js/jquery.js"></script>
    </head>
    
    <body id="logincont">
    	<div id="container">
        	<img src="images/container_top.gif" width="880" height="12" style="float:left" />
            	<h1>RSS源新浪微博定时发布系统</h1>
                <div id="login">
                	<img src="<?php echo $root_path;?>images/login_top.jpg" height="9" width="514" style="float:left" />
                		<span id="loginname">登录系统</span>
                		
                		<?php if($login_success){
                		?>
                			<span id="reg_msg" style="background: #A5C639; float:left; color: white;padding: 10px;width: 400px;font-size: 16px;
                        		-webkit-border-radius: 6x;-moz-border-radius: 6px;border-radius: 6px; margin: 20px;">
                        		您已登录成功，浏览器正在为您跳转到主页，请稍后！<br />
                        		您也可以<a href="index.php">点击这里</a>跳到主页！
                        	</span>
                		<?php
                		}?>
                		
                        <form method="post" action="" id="loginform" <?php if ($login_success) echo 'style="display: none;"' ?>>
                        	<?php if ($login_error){
                        	?>
                        	<span style="background: #FF6D37; color: white;padding: 10px;width: 400px;font-size: 16px;-webkit-border-radius: 6x;-moz-border-radius: 6px;border-radius: 6px;"><?php echo $login_error;?></span>
                        	<?php
                        	}?>
                        	<span>
                            	<label for="username">用户名:</label>
                            	<input type="text" name="username" id="username" class="inputbg" />
                            </span>
                            <span>
                                <label for="password">密码:</label>
                                <input type="password" name="password" id="password" class="inputbg" />
                            </span>
                            <input type="submit" value="登录" id="submit" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <a href="register.php">注册账号</a>
                        </form>
                    <img src="<?php echo $root_path;?>images/login_buttom.jpg" height="9" width="514" style="float:left" />
                </div>
        	<img src="<?php echo $root_path;?>images/container_buttom.gif" width="880" height="12" style="float:left;" />
        </div>
    </body>
</html>
